
let GM = require('GM');
let sdk = window.sdk;
cc.Class({
    extends: cc.Component,

    properties: {

        thanFriends : cc.Node,
        history : cc.Label,
        score : cc.Label,
        distance : cc.Label,
        integral : cc.Label,
        rank : cc.Label,
        thannum : cc.Label,
        thanScore : cc.Label,
        arrow : cc.Node,
        Thannum : cc.Node,
        Highest : cc.Node,
        //头像框
        smallframe:cc.Node,
        small:[cc.Prefab],
        //新纪录标志
        highlogo:cc.Node,
        //等级
        a:cc.Node,
        b:cc.Node,
        c:cc.Node,
        s:cc.Node,
    },
    // LIFE-CYCLE CALLBACKS:

    // onLoad () {},
    initInfo(data)
    {
        if(data.score > data.history)
        {
            this.Highest.active = true;
            cc.log(data.score > data.history);
        }
        if(data.thanNum)
        {
            this.arrow.active = true;
            this.Thannum.active = true;
        }
        if(data.score >= data.history){
            this.highlogo.active = true;
        }
        if(data.score < 50000){
            this.c.active = true;
        }else if(data.score < 100000){
            this.b.active = true;
        }else if(data.score < 150000){
            this.a.active = true;
        }else{
            this.s.active = true;
        }
        
        this.history.string = data.history;
        this.score.string = data.score;
        this.distance.string = data.distance;
        this.integral.string = data.integral;
        this.rank.string = data.rank;
        this.thannum.string = data.uprank;
        this.thanScore.string = data.beforescore;
        //this.thanFriends.getComponent('thanFriends').updateState(data.thanNum);
    },
    start ()
    {
        if(window.sdk){
            sdk.uploadingScore({
                score: GM.s,
                success:(res) => {
                    let data = res;
                    this.initInfo({
                        history : data.highScore, //历史分数
                        score : data.score,   //得分
                        distance : GM.distance, //距离
                        integral : data.score,  //积分
                        rank : data.rank,        //当前排名
                        uprank : data.uprank,       //上升排名
                        beforescore : data.beforescore,      //距离上一名
                    });
                },
                fail:(res) => {

                }
            })
        }
        
        
        //头像
       let index = GM.roleIndex;
       let smallrole = cc.instantiate(this.small[index]);
       smallrole.parent = this.smallframe;
     
       //预加载
       cc.director.preloadScene('Main', function() {
           
       });
    },

    //返回主界面
    onMain(){
        cc.director.loadScene('Main');
    },

    update (dt)
    {
        
    },
});
